home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / metkit / kbound.h < prev    next >
C/C++ Source or Header  |  1997-06-07  |  4KB  |  83 lines

  1. //    Copyright (C) 1996, 1997 Meta Four Software.  All rights reserved.
  2. //
  3. //  KitBinder embedded data support, public interface
  4. //
  5. //! rev="$Id: kbound.h,v 1.4 1997/05/27 10:42:39 jcw Rel $"
  6.  
  7. /////////////////////////////////////////////////////////////////////////////
  8. //
  9. //    Embedding a MetaKit datafile inside an executable file.
  10. //
  11. //    The c4_BoundStorage class can be used to access read-only data which
  12. //    has been stored as part of an executable file.  In a way, this makes
  13. //    MetaKit suitable as a form of platform-independent resource manager,
  14. //    with all the data structures and manipulation of MetaKit thrown in.
  15. //
  16. //    All stored data is also compressed using a simple, very fast variation
  17. //    of Lempel-Zev compression (by Ross N. Williams), and can optionally be
  18. //    encoded using a custom function (defined by c4_BoundStorage::_Encoder).
  19. //
  20. //    To use this embedding, you need to have a regular MetaKit datafile and
  21. //    "bind" it to the executable.  On Windows, data is stored in resources.
  22. //    Only Win 16/32 is currently supported, Macintosh support should be very
  23. //    easy to add, other platforms may need more work (to simulate resources).
  24. //
  25. //    A tiny command-line utility called "KitBinder" is used to generate files
  26. //    which can then be linked into the application by the resource linker.
  27. //    KitBinder has to be run each time you want to alter the bound data.
  28. //
  29. //    The process of switching to bound data is quite simple:
  30. //
  31. //        1.  Presumably, you have a MetaKit datafile with some data in it.
  32. //            Let's assume it is now stored in a file called "try.dat".
  33. //        2.  Create source files for the resource editor (if on Win 32):
  34. //                kbinder try.dat kbtry
  35. //            Or, for Win16, use a text format instead:
  36. //                kbinder -t try.dat kbtry
  37. //        3.  This produces a file called "kbtry.rc", as well as one or more
  38. //            files called "kbtryXXX.res" (or "kbtryXXX.rc" if text format).
  39. //        4.  Add the following line to your application resource file:
  40. //                #include "kbtry.rc"
  41. //        5.  Include the file "kbound.h" to define the c4_BoundStorage class,
  42. //            and include the code which is in "kbound.cpp" in your project.
  43. //        6.  Create your storage object from the class "c4_BoundStorage",
  44. //            instead of "c4_Storage", and omit parameters, ie. change this:
  45. //                c4_Storage myStorage ("try.dat", false);
  46. //            to:
  47. //                c4_BoundStorage myStorage;
  48. //        7.  That's it, you now have a read-only copy of "try.dat" bound to
  49. //            your application and no longer need that data file at run time.
  50. //            Everything will continue to work, but you cannot commit changes.
  51. //            You can however call DumpAsRes, or c4_Storage::SaveToStream.
  52. //
  53. //    For the original comments about the compression code, see "kboundw.cpp".
  54. //
  55. //    To use encoding, you need to point c4_BoundStorage::_Encoder to an
  56. //    appropriate function before creating any instances of c4_BoundStorage.
  57. //
  58. /////////////////////////////////////////////////////////////////////////////
  59.  
  60. #ifndef __KBOUND_H__
  61. #define __KBOUND_H__
  62.  
  63. #include <m4kit.h>
  64.  
  65. class c4_BoundStorage : public c4_Storage
  66. {
  67. public:
  68.     enum { kBlockSize = 10000 };      
  69.  
  70.     c4_BoundStorage (int base_ =100);
  71.     ~c4_BoundStorage ();
  72.  
  73.     static int DumpAsRes(c4_Storage& orig_, const char* prefix_, 
  74.                             bool asText_ =false, int base_ =100);
  75.  
  76.         // this can be set to a function which implements encoding/decoding
  77.     static void (*_Encoder)(bool,int,char*,int);
  78. };
  79.  
  80. /////////////////////////////////////////////////////////////////////////////
  81.  
  82. #endif
  83.